package com.hc.controller;

import com.hc.entity.Payment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("/consumer")
public class OrderController {

    @Resource
    private RestTemplate restTemplate;

    private final String payment_url = "http://localhost:8081";

    @PostMapping("/create")
    public Result<Payment> create(Payment payment) {
        return restTemplate.postForObject(payment_url + "/provider/create", payment, Result.class);
    }

    @GetMapping("/get/{id}")
    public Result<Payment> get(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(payment_url + "provider/get/" + id, Result.class);
    }
}
